package com.huixi.Enums;

import java.util.HashMap;
import java.util.Map;

public enum JsonStatus {
	SUCCESS(200, "成功"), 
	WARNING(201, "失败"), 
	ERROR(400, "失败");
	private Integer code;
	private String desc;

	public Integer getCode() {
		return this.code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getDesc() {
		return this.desc;
	}

	public void setMessage(String desc) {
		this.desc = desc;
	}

	JsonStatus(Integer code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public static JsonStatus getByKey(Integer code) {
		if (code == null) {
			return null;
		}
		for (JsonStatus type : values()) {
			if (type.getCode() == code)
				return type;
		}
		return null;
	}

	public static Map<Integer, String> toMap() {
		Map<Integer, String> enumDataMap = new HashMap<Integer, String>();
		for (JsonStatus key : values()) {
			enumDataMap.put(key.getCode(), key.getDesc());
		}
		return enumDataMap;
	}
}
